<template>
	<view class="applyInfo">
		<u-navbar title="维修申请列表" back-icon-color="#fff"
			:background="{backgroundImage: 'linear-gradient(45deg, #68dae7, #21a4b3)'}" title-color="#FFFFFF">
		</u-navbar>
		<view class="applyInfo-form">
			<u-form :model="checkInfo" label-width="180rpx" >
				<u-form-item label="仪器名称"><u-input v-model="applyInfo.deviceName" disabled/></u-form-item>
				<u-form-item label="资产编号"><u-input v-model="applyInfo.serialNumber" disabled/></u-form-item>
				
				<u-form-item label="申请人"><u-input v-model="applyInfo.applyPeople" placeholder=" " disabled/></u-form-item>
				<u-form-item label="申请人手机号"><u-input v-model="applyInfo.applyPhone" placeholder=" " disabled/></u-form-item>
				<u-form-item label="报修原因">
					<u-input type="textarea" :height="240" v-model="applyInfo.applyReason" placeholder=" " disabled/>
				</u-form-item>
				<u-form-item label="维修人" v-if="role == 'admin'">
					<view >
						<u-input @click="show = true"  v-model="rapirName"  placeholder="请选择" disabled/>
					</view>
				</u-form-item>
			</u-form>
			<view class="applyInfo-form-img" style="padding-top: 0;">
				<view class="deviceInfo-img-title">报修照片:</view>
				<image class="devicePng" mode="widthFix" @click="previewImage(applyInfo.applyPic)" :src="applyInfo.applyPic"></image>
				<!-- <image class="devicePng" mode="widthFix" @click="previewImage(`/static/images/deviceInfo1.jpg`)" src="/static/images/deviceInfo1.jpg"></image> -->
			</view>
			<u-select v-model="show" :list="list" @confirm="chooseUser"></u-select>
		</view>
		<view class="applyInfo-btn" @tap="assginRepair" v-if="role == 'admin'">
			确定
		</view>
		<u-toast ref="uToast"></u-toast>
	</view>
</template>

<script>
	export default{
		data(){
			return {
				show:false,
				rapirName:"",
				list:[],
				userId:null,
				applyInfo:{},
				role: uni.getStorageSync("role")
			}
		},
		onLoad(options) {
			this.applyId = options.id
			this.getData()
		},
		methods:{
			getData(){
				let params = {
					id:this.applyId
				}
				this.$xt.api.deviceCheckDetail(params).then(res=>{
					this.applyInfo = res.data
				})
				this.$xt.api.userList().then(res=>{
					if(res.data.length>0){
						res.data.forEach(item=>{
							let obj = {
								value:item.userId,
								label:item.name
							}
							this.list.push(obj)
						})
						
					}
				})
				
			},
			chooseUser(data){
				console.log(data)
				this.rapirName = data[0].label
				this.userId = data[0].value
			},
			previewImage(url){
				uni.previewImage({
					current: url,
					urls:[url]
				})
			},
			assginRepair(){
				if(!this.userId){
					this.$refs.uToast.show({
						title:"请选择维修人员",
						duration:2000,
						type:"error"
					})
					return
				}
				let params = {
					userId: this.userId,
					id:this.applyId
				}
				this.$xt.api.deviceCheckSign(params).then(res=>{
					this.$refs.uToast.show({
						title:"操作成功",
						duration:1000,
						type:"success"
					})
					let page = getCurrentPages(),
					currentPages = page[page.length - 2]
					setTimeout(()=>{
						currentPages.$vm.getData()
						this.$u.route({type: 'back'})
					},1000)
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	
	.applyInfo{
		position: relative;
		&-form{
			background-color: #fff;
			padding: 10rpx 24rpx;
		}
		&-btn{
			position: fixed;
			bottom: 0;
			width: 100%;
			padding: 20rpx 24rpx 40rpx 24rpx;
			display: flex;
			justify-content: space-around;
			border-radius: 20rpx 20rpx 0 0;
			background-color: #00aa00;
			color:#fff
		}
	}
</style>